/**
 * 2017年4月27日
 */
package com.zhaogang.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.view.UrlBasedViewResolver;

import com.zhaogang.entity.Page;
import com.zhaogang.entity.SystemLog;
import com.zhaogang.service.SystemLogService;

/**
 * @author xiao.shu
 *2017年4月27日 下午2:54:17
 */
@Controller
@RequestMapping(value = "/log")
public class SystemLogServiceController {
	@Autowired
	private SystemLogService systemLogService;
	
	
/**
 * 查询日志
 * @param model
 * @return
 */
/*	@RequestMapping(value = "/log", method = RequestMethod.GET)
	public Object query(Page page,Model model) {
        Page p= systemLogService.findPage(page);
		page.setTotalCount(p.getTotalCount());
		page.setTotalPageCount(p.getTotalPageCount());
		List<SystemLog> list = systemLogService.query(p);
		model.addAttribute("list",list);
		return "/admin/log";
		
	}*/
	/**
	 * 删除日志
	 */
	@RequestMapping(value="/deleteLog")
	public String deleteLog(Integer id){
		 systemLogService.deleteLog(id);	 
		 return  UrlBasedViewResolver.REDIRECT_URL_PREFIX+"/log/queryLogByCon";
			
	}
	/**
	 * 条件查询日志
	 */
@RequestMapping(value="queryLogByCon")
	public Object queryLogByCon( Integer id,String userName,Model model,Page page,HttpServletRequest request){
	model.addAttribute("listid", id);
	model.addAttribute("listname", userName);
	if(id == null & userName == null){
		Page p=systemLogService.findPage(page);
		page.setTotalCount(p.getTotalCount());
		page.setTotalPageCount(p.getTotalPageCount());
		List<SystemLog> list = systemLogService.query(p);
		model.addAttribute("list",list);
		return "/admin/log";
	}
	else{
		Page p= systemLogService.findPage1(page,id,userName);
		page.setTotalCount(p.getTotalCount());
		page.setTotalPageCount(p.getTotalPageCount());
		model.addAttribute("listid", id);
		model.addAttribute("listname", userName);
		List<SystemLog> list=systemLogService.queryLogByCon(id,userName,page);
		model.addAttribute("list",list);
		return "/admin/log";
	}

}





}
	

